<template>
  <div class="user">
    <div class="user-top" v-if="loginStatus">   
      <div class="info">
        <img src="@/assets/image/user.png" alt="" />
        <div class="user-desc">
          <span>登录名:{{ userInfo.userInfo.username }}</span>
          <span>手机号:   {{ userInfo.userInfo.phone }}</span> 
        </div>
      </div>
      <ul class="user-list">
        <li class="van-hairline--bottom" @click="goTo('/setting')">
          <span>账号管理</span>
          <van-icon name="arrow" />
        </li>
        <li @click="goTo('/about')">
          <span>关于我们</span>
          <van-icon name="arrow" />
        </li>
      </ul>
      <van-button
        round
        class="save-btn"
        color="red"
        type="primary"
        @click="handleLogout"
        block
        >退出登录</van-button
      >
    </div>
  </div>
</template>
<script>
import { mapState,mapMutations } from "vuex";
export default {
  data() {
    return {

    };
  },
  created() {
      // const userInfo = JSON.parse(localStorage.getItem("userInfo")) || null;//从本地存储获取信息
      // console.log(userInfo);
  },
  computed: {
    ...mapState({
      loginStatus: (state) => state.user.loginStatus,
      userInfo: (state) => state.user.userInfo,
    }),
  },
  methods: {
    ...mapMutations(['loginOut']),
    handleLogout() {
      this.loginOut();
      window.location.href = '/'
    }
  },

};
</script>
<style lang="less" scoped>
@import url("../assets/css/style.less");
.user-top {
  width: 94%;
  margin: 10px;
  height: 115px;
  background: rgb(231, 47, 47);
  box-shadow: 0 2px 5px #269090;
  border-radius: 6px;
  .info {
    position: relative;
    display: flex;
    width: 100%;
    padding: 25px 20px;
    box-sizing: border-box;
    img {
      .w(60px);
      .h(60px);
      border-radius: 50%;
      margin-top: 4px;
    }
    .user-desc {
      display: flex;
      flex-direction: column;
      margin-left: 40px;
      line-height: 20px;
      font-size: 14px;
      color: #fff;
      span {
        color: #fff;
        font-size: 14px;
        padding: 2px 0;
      }
    }
    .account-setting {
      position: absolute;
      top: 10px;
      right: 20px;
      font-size: 13px;
      color: #fff;
      .van-icon-setting-o {
        font-size: 16px;
        vertical-align: -3px;
        margin-right: 4px;
      }
    }
  }
  .user-list {
    padding: 0 20px;
    margin: 16px 10px;
    li {
      height: 40px;
      line-height: 40px;
      display: flex;
      justify-content: space-between;
      font-size: 14px;
      .van-icon-arrow {
        margin-top: 13px;
      }
    }
  }
}
</style>
